package com.hyts.network.server;


import java.util.Objects;


import com.hyts.network.base.ServerFactoryBean;
import com.hyts.network.config.DefaultNetwork;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;

/** 
 * @author LiBo/Alex
 * @see com.hyts.network.base.ServerFactoryBean<ServerBootstrap>
 * @since V1.0
 * @version V1.0 
 * Netty服务操作工厂对象
 */  
public abstract class NettyServiceFactoryBean<T> extends ServerFactoryBean<ServerBootstrap> {

	/**
	 * @fieldName serverEventLoopGroup
	 * @fieldType EventLoopGroup
	 */ 
	private EventLoopGroup bossEventLoopGroup;
	
	/**  
	 * @fieldName clientEventLoopGroup
	 * @fieldType EventLoopGroup
	 */ 
	private EventLoopGroup workEventLoopGroup;
	
	private T threadPool;
	
	/**
	 * default port 80
	 */
	public NettyServiceFactoryBean() {
		super(DefaultNetwork.DEFAULT_NETWORK_LOCAL_PORT, new ServerBootstrap());
		this.bossEventLoopGroup = new NioEventLoopGroup();
		this.workEventLoopGroup = new NioEventLoopGroup();
	}
	/**
	 * @param port
	 */
	public NettyServiceFactoryBean(int port) {
		super(port, new ServerBootstrap());
		this.bossEventLoopGroup = new NioEventLoopGroup();
		this.workEventLoopGroup = new NioEventLoopGroup();
	}
	
	/**
	 * @param port
	 * @param server
	 */
	public NettyServiceFactoryBean(int port, ServerBootstrap server) {
		super(port, Objects.isNull(server)?new ServerBootstrap():server);
		this.bossEventLoopGroup = new NioEventLoopGroup();
		this.workEventLoopGroup = new NioEventLoopGroup();
	}

	/**
	 * @param server
	 * @param singleCpuThreadNum
	 * @param tryReconnectedTimes 尝试重试连接次数
	 */
	public NettyServiceFactoryBean(ServerBootstrap server, int singleCpuThreadNum, int tryReconnectedTimes) {
		super(Objects.isNull(server)?new ServerBootstrap():server, singleCpuThreadNum, tryReconnectedTimes);
		this.bossEventLoopGroup = new NioEventLoopGroup(singleCpuThreadNum);
		this.workEventLoopGroup = new NioEventLoopGroup(singleCpuThreadNum);
	}

	/**
	 * @param server
	 * @param singleCpuThreadNum
	 */
	public NettyServiceFactoryBean(ServerBootstrap server, int singleCpuThreadNum) {
		super(Objects.isNull(server)?new ServerBootstrap():server, singleCpuThreadNum);
		this.bossEventLoopGroup = new NioEventLoopGroup(singleCpuThreadNum);
		this.workEventLoopGroup = new NioEventLoopGroup(singleCpuThreadNum);
	}

	/**
	 * @param server
	 */
	public NettyServiceFactoryBean(ServerBootstrap server) {
		super(Objects.isNull(server)?new ServerBootstrap():server);
		this.bossEventLoopGroup = new NioEventLoopGroup();
		this.workEventLoopGroup = new NioEventLoopGroup();
	}
	/***************getter or setter 对象*****************************/
	public EventLoopGroup getBossEventLoopGroup() {
		return bossEventLoopGroup;
	}
	public void setBossEventLoopGroup(EventLoopGroup bossEventLoopGroup) {
		this.bossEventLoopGroup = bossEventLoopGroup;
	}
	public EventLoopGroup getWorkEventLoopGroup() {
		return workEventLoopGroup;
	}
	public void setWorkEventLoopGroup(EventLoopGroup workEventLoopGroup) {
		this.workEventLoopGroup = workEventLoopGroup;
	}
	public T getThreadPool() {
		return threadPool;
	}
	public void setThreadPool(T threadPool) {
		this.threadPool = threadPool;
	}
}
